home *** CD-ROM | disk | FTP | other *** search
/ SGI SNMP Access to HP-UX MIB 1.1.2 / SGI SNMP Access to HP-UX MIB 1.1.2.iso / dist / pcp_eoe.idb / usr / sbin / pmafm.z / pmafm
Text File  |  1998-04-24  |  12KB  |  566 lines

  1. #!/bin/sh
  2. #Tag 0x00010D0C
  3. #
  4. # Copyright 1995, Silicon Graphics, Inc.
  5. # ALL RIGHTS RESERVED
  6. # UNPUBLISHED -- Rights reserved under the copyright laws of the United
  7. # States.   Use of a copyright notice is precautionary only and does not
  8. # imply publication or disclosure.
  9. # U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND:
  10. # Use, duplication or disclosure by the Government is subject to restrictions
  11. # as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights
  12. # in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or
  13. # in similar or successor clauses in the FAR, or the DOD or NASA FAR
  14. # Supplement.  Contractor/manufacturer is Silicon Graphics, Inc.,
  15. # 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311.
  16. # THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY
  17. # INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION,
  18. # DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY
  19. # PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON
  20. # GRAPHICS, INC.
  21. #
  22. # $Id: pmafm,v 2.8 1998/01/05 19:44:03 kenmcd Exp $
  23.  
  24. # Some degree of paranoia here ...
  25. PATH=/usr/sbin:/usr/bsd:/sbin:/usr/bin:/bin:/usr/pcp/bin
  26. export PATH
  27.  
  28. _usage()
  29. {
  30.     echo "Usage: pmafm folioname [command [arg ...]]"
  31. }
  32.  
  33. _help()
  34. {
  35.     echo \
  36. 'PCP Archive Folio Manager
  37.  
  38. Commands:
  39.   archives        - select all archives
  40.   archives N[,...]    - select archives with these ordinal numbers
  41.   archives name[,...]    - select archives with these names
  42.   check            - integrity check for folio
  43.   help            - this message
  44.   hosts         - select archives for all hosts (the default)
  45.   hosts hostname[,...]    - select archives for just these hosts
  46.   list [verbose]    - display folio contents
  47.   quit            - exit
  48.   remove        - echo the sh(1) command to delete all files
  49.               associated with the folio
  50.   repeat tool [arg ...]    - execute a known PCP tool on each archive in turn
  51.   replay        - replay archives using the tool that created the folio
  52.   [run] tool [arg ...]    - execute a known PCP tool on the selected archives
  53.   selections        - list selected archives
  54.   
  55. Selection:
  56.   If specified, both the "archives" and the "hosts" selection criteria
  57.   are applied as a conjunction.'
  58. }
  59.  
  60. if [ $# -lt 1 ]
  61. then
  62.     _usage 1>&2
  63.     exit 1
  64. fi
  65.  
  66. if [ ! -f $1 ]
  67. then
  68.     if [ "X$1" = "X-?" ]
  69.     then
  70.     _usage 1>&2
  71.     echo
  72.     _help 1>&2
  73.     else
  74.     echo "pmafm: cannot open folio \"$1\"" 1>&2
  75.     fi
  76.     exit 1
  77. fi
  78.  
  79. _FOLIOPATH=`dirname $1`
  80. if [ "$_FOLIOPATH" = "." ]
  81. then
  82.     _FOLIOPATH=""
  83. elif [ -d $_FOLIOPATH ]
  84. then
  85.     _TMP=`pwd`
  86.     cd $_FOLIOPATH
  87.     _FOLIOPATH=`pwd`/
  88.     cd $_TMP
  89. fi
  90. _FOLIO="$1"
  91. _FOLIONAME=`basename $_FOLIO`
  92.  
  93. # if /etc/magic was safe on all IRIXes and included the PCP file typing
  94. # extensions, could use file(1) instead of grep(1)
  95. #
  96. if grep '^PCPFolio' $1 >/dev/null && grep '^Version:' $1 >/dev/null
  97. then
  98.     :
  99. else
  100.     echo "pmafm: \"${_FOLIOPATH}$_FOLIONAME\" is not in PCP archive folio format" 1>&2
  101.     exit 1
  102. fi
  103.  
  104. _HOSTS=""
  105. _ALL_HOSTS=`nawk <$_FOLIO '$1 == "Archive:" { printf " %s",$2 }'; echo | sort -u`
  106. _ARCHIVES=""
  107. _ALL_ARCHIVES=`nawk <$_FOLIO '$1 == "Archive:" { printf " %s",$3 }'; echo`
  108. _DEBUG=false
  109. export _DEBUG _FOLIO _HOSTS _ALL_HOSTS _ARCHIVES _ALL_ARCHIVES
  110.  
  111. _SINGLE=""
  112. _MULTI=""
  113. _REPLAY=""
  114. _SPECIAL=""
  115.  
  116. # collect names of known tools, and "run" scripts for each
  117. #
  118. for config in /var/pcp/config/pmafm/* $HOME/.pcp/pmafm/*
  119. do
  120.     if [ "$config" = '/var/pcp/config/pmafm/*' ]
  121.     then
  122.     echo "pmafm: Warning: no PCP tool configurations in /var/pcp/config/pmafm/"
  123.     elif [ "$config" = "$HOME/.pcp/pmafm/"'*' ]
  124.     then
  125.     # no user defined list of tools
  126.     :
  127.     else
  128.     SINGLE=""
  129.     MULTI=""
  130.     REPLAY=""
  131.     SPECIAL=""
  132.     . $config
  133.     [ ! -z "$SINGLE" ] && _SINGLE="$_SINGLE $SINGLE"
  134.     [ ! -z "$MULTI" ] && _MULTI="$_MULTI $MULTI"
  135.     [ ! -z "$REPLAY" ] && _REPLAY="$_REPLAY $REPLAY"
  136.     [ ! -z "$SPECIAL" ] && _SPECIAL="$_SPECIAL $SPECIAL"
  137.     fi
  138. done
  139.  
  140. tmp=/tmp/$$
  141. trap "rm -f $tmp; exit" 0 1 2 3 15
  142.  
  143. _check_file()
  144. {
  145.     if [ ! -f "$1" ]
  146.     then
  147.     echo "No such file: $1" >>$tmp
  148.     else
  149.     dd ibs=1 count=7 if="$1" 2>/dev/null | od -X | nawk '
  150. NR == 1 && $2 == "00000084" && $3 == "50052600" { exit 0 }
  151.                         { exit 1 }'
  152.     if [ $? -eq 0 ]
  153.     then
  154.         :
  155.     else
  156.         echo "Not a PCP archive file: $1" >>$tmp
  157.     fi
  158.     fi
  159. }
  160.  
  161. _check()
  162. {
  163.     sed -n '/^Archive:/p' <$_FOLIO \
  164.     | while read xxx host arch
  165.     do
  166.     rm -f $tmp
  167.     path=`_fix_arch_path "" $arch`
  168.     echo "Archive: $path ... \c"
  169.     _check_file $path.index
  170.     _check_file $path.meta
  171.     _check_file $path.0
  172.     if [ ! -s $tmp ]
  173.     then
  174.         realhost=`pmdumplog -l $path | sed -n -e '/^Performance metrics/s/.* host //p'`
  175.         [ "X$host" != "X$realhost" ] && \
  176.         echo "Hostname mismatch: folio=$host archive=$realhost" >>$tmp
  177.     fi
  178.     if [ -s $tmp ]
  179.     then
  180.         echo "Errors"
  181.         sed -e 's/^/    /' $tmp
  182.     else
  183.         echo "OK"
  184.     fi
  185.     done
  186. }
  187.  
  188. _dir()
  189. {
  190.     echo
  191.     echo "PCP Archive Folio: $_FOLIONAME"
  192.     [ ! -z "$_FOLIOPATH" ] && echo "Folio Directory: $_FOLIOPATH"
  193.     nawk <$_FOLIO '
  194. $1 == "Created:"    { print; next }
  195. $1 == "Creator:"    { print; next }'
  196.     echo
  197.     echo "Ordinal Hostname             Archive Basename"
  198.     i=1
  199.     sed -n '/^Archive:/p' $_FOLIO \
  200.     | while read xxx host archive
  201.     do
  202.     printf "  [%3s] %-20s %s\n" $i $host $archive
  203.     [ "X$1" = "Xverbose" ] && pmdumplog -l `_fix_arch_path "" $archive` | sed -e 's/^/    /'
  204.     i=`expr $i + 1`
  205.     done
  206. }
  207.  
  208. # $1 is separater
  209. #
  210. _fix_arch_path()
  211. {
  212.     sep="$1"
  213.     shift
  214.     archlist=""
  215.     for arch
  216.     do
  217.     if [ ! -z "$_FOLIOPATH" ]
  218.     then
  219.         case $arch
  220.         in
  221.         /*)
  222.             ;;
  223.         *)
  224.             arch=${_FOLIOPATH}$arch
  225.             ;;
  226.         esac
  227.     fi
  228.     if [ -z "$archlist" ]
  229.     then
  230.         archlist="${arch}"
  231.     else
  232.         archlist="${archlist}${sep}${arch}"
  233.     fi
  234.     done
  235.  
  236.     echo $archlist
  237. }
  238.  
  239. _get_archlist()
  240. {
  241.     if [ -z "$_ARCHIVES" ]
  242.     then
  243.     archlist="$_ALL_ARCHIVES"
  244.     else
  245.     archlist="$_ARCHIVES"
  246.     fi
  247.  
  248.     if [ ! -z "$_HOSTS" ]
  249.     then
  250.     newlist=""
  251.     for arch in $archlist
  252.     do
  253.         host=`nawk <$_FOLIO '$3 == "'$arch'" { print $2; exit }'`
  254.         if echo "$_HOSTS " | grep " $host " >/dev/null
  255.         then
  256.         newlist="$newlist $arch"
  257.         fi
  258.     done
  259.     archlist=$newlist
  260.     fi
  261.  
  262.     echo $archlist
  263. }
  264.  
  265. _replay()
  266. {
  267.     _CREATOR=""
  268.     _REPLAY_CONFIG=""
  269.     eval `sed -n <$_FOLIO -e '/^Creator:/{
  270. s/Creator:[     ]*//
  271. s/^/_CREATOR=/
  272. s/[     ][     ]*/ _REPLAY_CONFIG=/
  273. p
  274. }'`
  275.     if [ -z "$_CREATOR" ]
  276.     then
  277.     echo "Error: cannot determine folio creator"
  278.     return
  279.     else
  280.     if [ ! -z "$_REPLAY_CONFIG" ]
  281.     then
  282.         _REPLAY_CONFIG=`_fix_arch_path "" "$_REPLAY_CONFIG"`
  283.         echo "Configuration File: $_REPLAY_CONFIG"
  284.         if [ ! -f "$_REPLAY_CONFIG" ]
  285.         then
  286.         echo "Error: cannot find Configuration File"
  287.         return
  288.         fi
  289.     fi
  290.     fi
  291.  
  292.     if echo "$_REPLAY " | grep " $_CREATOR " >/dev/null
  293.     then
  294.         if [ -z "$_REPLAY_CONFIG" ]
  295.     then
  296.         _run $_CREATOR
  297.     else
  298.         _run $_CREATOR -c $_REPLAY_CONFIG
  299.     fi
  300.     else
  301.     echo "Error: I don't know how to replay a folio created by \"$_CREATOR\""
  302.     echo "       ... choose a PCP tool and use the \"run\" command to replay"
  303.     fi
  304. }
  305.  
  306. _known()
  307. {
  308.     echo "Known PCP tools:"
  309.     echo "$_SINGLE$_MULTI" \
  310.     | sed -e 's/^ *//' \
  311.     | tr ' ' '\012' \
  312.     | sort \
  313.     | fmt \
  314.     | sed -e 's/^/    /'
  315. }
  316.  
  317. _run()
  318. {
  319.     tool=$1
  320.     tool_basename=`basename $tool`
  321.     shift
  322.     archlist=`_get_archlist`
  323.     if [ -z "$archlist" ]
  324.     then
  325.     echo "Error: no selected archives"
  326.     return
  327.     fi
  328.  
  329.     if $_REPEAT || ( echo "$_SINGLE " | grep " $tool_basename " >/dev/null )
  330.     then
  331.     n_arch=`echo $archlist | wc -w | sed -e 's/  *//g'`
  332.     [ "$n_arch" -gt 1 ] && echo "Note: running $tool serially, once per archive"
  333.     for arch in $archlist
  334.     do
  335.         nawk <$_FOLIO '$3 == "'$arch'" { printf "Host: %s",$2; exit }'
  336.         path=`_fix_arch_path "" "$arch"`
  337.         echo " Archive: $path"
  338.         # arrgh ... special case for pmdumplog where -a is something else
  339.         # and archive comes last ... sigh
  340.         #
  341.         _done=false
  342.         if [ ! -z "$_SPECIAL" ]
  343.         then
  344.         for special in $_SPECIAL
  345.         do
  346.             if [ "$tool_basename" = "$special" ]
  347.             then
  348.             $tool $* $path
  349.             _done=true
  350.             break
  351.             fi
  352.         done
  353.         fi
  354.  
  355.         if $_done
  356.         then
  357.         :
  358.         else
  359.         $tool -a $path $*
  360.         fi
  361.     done
  362.     elif echo "$_MULTI " | grep " $tool_basename " >/dev/null
  363.     then
  364.     $tool -a `_fix_arch_path "," $archlist` $*
  365.     elif [ "X$tool" = "X_show_me_" ]
  366.     then
  367.     for arch in $archlist
  368.     do
  369.         path=`_fix_arch_path "" "$arch"`
  370.         echo "Archive: $path"
  371.     done
  372.     else
  373.     echo "Sorry, don't know how to run \"$tool\" ..."
  374.     fi
  375. }
  376.  
  377. _MORE=true
  378. while $_MORE
  379. do
  380.     if [ $# -gt 1 ]
  381.     then
  382.     shift
  383.     cmd="$1"
  384.     shift
  385.     args=$*
  386.     _MORE=false
  387.     else
  388.     echo "pmafm> \c"
  389.     read cmd args
  390.     if [ $? -ne 0 ]
  391.     then
  392.         echo
  393.         break
  394.     elif [ -z "$cmd" ]
  395.     then
  396.         continue
  397.     fi
  398.     fi
  399.  
  400.     _REPEAT=false
  401.     if echo "$_SINGLE $_MULTI " | grep " $cmd " >/dev/null
  402.     then
  403.     # recognized command
  404.     _run $cmd $args
  405.     else
  406.     case $cmd
  407.     in
  408.  
  409.         a|ar|arch|archi|archiv|archive|archives)
  410.             case $args
  411.             in
  412.             '')
  413.                 _ARCHIVES=""
  414.                 ;;
  415.             *)
  416.                 _ARCHIVES=""
  417.                 for arch in `echo $args | sed -e 's/,/ /g'`
  418.                 do
  419.                 _TMP=`nawk <$_FOLIO '
  420.     $1 == "Archive:"    { if ("'$arch'" == $3) {
  421.                 print $3
  422.                 exit
  423.                   }
  424.                   i++
  425.                   if ("'$arch'" == i) {
  426.                 print $3
  427.                 exit
  428.                   }
  429.                 }'`
  430.                 if [ -z "$_TMP" ]
  431.                 then
  432.                     echo "Warning: archive \"$arch\" not in folio ... ignored"
  433.                 else
  434.                     _ARCHIVES="$_ARCHIVES $_TMP"
  435.                 fi
  436.                 done
  437.                 ;;
  438.             esac
  439.             ;;
  440.  
  441.         c|ch|che|chec|check)
  442.             _check
  443.             ;;
  444.  
  445.         d|de|deb|debu|debug)
  446.             if $_DEBUG
  447.             then
  448.             _DEBUG=false
  449.             set -
  450.             else
  451.             _DEBUG=true
  452.             set -x
  453.             fi
  454.             ;;
  455.  
  456.         \?|he|hel|help)
  457.             _help
  458.             ;;
  459.  
  460.         ho|hos|host|hosts)
  461.             case $args
  462.             in
  463.             '')
  464.                 _HOSTS=""
  465.                 ;;
  466.             *)
  467.                 _HOSTS=""
  468.                 for host in `echo $args | sed -e 's/,/ /g'`
  469.                 do
  470.                 if echo "$_ALL_HOSTS " | grep " $host " >/dev/null
  471.                 then
  472.                     _HOSTS="$_HOSTS $host"
  473.                 else
  474.                     echo "Warning: host \"$host\" not in folio ... ignored"
  475.                 fi
  476.                 done
  477.                 ;;
  478.             esac
  479.             ;;
  480.  
  481.         l|li|lis|list)
  482.             case $args
  483.             in
  484.             v|ve|ver|verb|verbo|verbos|verbose)
  485.                 _dir verbose
  486.                 ;;
  487.             '')
  488.                 _dir
  489.                 ;;
  490.             *)
  491.                 echo "Illegal option \"$args\" ... ignored"
  492.                 _dir
  493.                 ;;
  494.             esac
  495.             [ ! -z "$_HOSTS" ] && echo "Host Selections:$_HOSTS"
  496.             [ ! -z "$_ARCHIVES" ] && echo "Archive Selections:$_ARCHIVES"
  497.             ;;
  498.  
  499.         q|qu|qui|quit)
  500.             break
  501.             ;;
  502.  
  503.         ru|run|repe|repea|repeat)
  504.             case $cmd
  505.             in
  506.             repe|repea|repeat)
  507.             _REPEAT=true
  508.             ;;
  509.             esac
  510.             tool=`echo "$args" | sed -e 's/ .*//'`
  511.             tool_basename=`basename $tool`
  512.             if [ -z "$tool" ]
  513.             then
  514.             echo "Error: missing PCP tool name"
  515.             _known
  516.             elif [ "X$tool" = 'X?' ]
  517.             then
  518.             _known
  519.             elif echo "$_SINGLE $_MULTI " | grep " $tool_basename " >/dev/null
  520.             then
  521.             _run $args
  522.             else
  523.             echo "Error: Unknown PCP tool: $tool"
  524.             _known
  525.             fi
  526.             ;;
  527.  
  528.         rem|remo|remov|remove)
  529.             [ ! -z "$_FOLIOPATH" ] && echo "( cd $_FOLIOPATH; \c"
  530.             echo "rm -f $_FOLIONAME\c"
  531.             nawk <$_FOLIO '$1 == "Creator:" && NF > 2    { printf " %s",$3; exit }'
  532.             for arch in $_ALL_ARCHIVES
  533.             do
  534.             echo " $arch.meta $arch.index\c"
  535.             path=`_fix_arch_path "" $arch`
  536.             pmdumplog -t $path 2>/dev/null \
  537.             | nawk '/^[0-9][0-9]:/ { print $2 }' \
  538.             | sort -u \
  539.             | while read vol
  540.             do
  541.                 echo " $arch.$vol\c"
  542.             done
  543.             done
  544.             [ ! -z "$_FOLIOPATH" ] && echo " )\c"
  545.             echo
  546.             ;;
  547.  
  548.         repl|repla|replay)
  549.             _replay
  550.             ;;
  551.  
  552.         s|se|sel|sele|selec|select|selecti|selectio|selection|selections)
  553.             _run _show_me_
  554.             ;;
  555.  
  556.         *)
  557.             echo "Unknown command \"$cmd\" ... enter \"help\" for more information"
  558.             ;;
  559.     esac
  560.     fi
  561. done
  562.  
  563.